package leetcode.editor.cn;
public class P372SuperPow {
    public static void main(String[] args) {
        Solution solution = new P372SuperPow().new Solution();solution.pow(10, 2);
        
    }
    
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
        static final int MOD = 1337;

        public int superPow(int a, int[] b) {
            int ans = 1;
            for (int i = b.length - 1; i >= 0; --i) {
                ans = (int) ((long) ans * pow(a, b[i]) % MOD);
                a = pow(a, 10);
            }
            return ans;
        }

        public int pow(int x, int n) {
            int res = 1;
            while (n != 0) {
                if (n % 2 != 0) {
                    res = (int) ((long) res * x % MOD);
                }
                x = (int) ((long) x * x % MOD);
                n /= 2;
            }
            return res;
        }

}
//leetcode submit region end(Prohibit modification and deletion)

}